package com.koala.user.controller;

import com.koala.common.annotation.Anonymous;
import com.koala.common.core.domain.AjaxResult;
import com.koala.common.core.domain.model.LoginUser;
import com.koala.common.utils.SecurityUtils;
import com.koala.web.domain.User;
import com.koala.web.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName: UserController
 * @Author: YuanDing
 * @Date: 2025/11/1 16:04
 * @Description:
 */

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private IUserService userService;


    /**
     * 登录
     * @param loginUser
     * @return
     */
    @PostMapping("login")
    public AjaxResult login(@RequestBody LoginUser loginUser) {
        User user = userService.login(loginUser);
        return AjaxResult.success(user);

    }

    /**
     * 注册
     * @param user
     * @return
     */
    @PostMapping("register")
    public AjaxResult register(@RequestBody User user) {
        boolean result = userService.register(user);
        return result ? AjaxResult.success(user) : AjaxResult.error();

    }

    /**
     * 注册
     * @param user
     * @return
     */
    @PutMapping("password")
    public AjaxResult modifyPassword(@RequestBody User user) {
        boolean result = userService.modifyPassword(user);
        return result ? AjaxResult.success(user) : AjaxResult.error();

    }


    /**
     * 获取用户详细信息
     * @param
     * @return
     */
    @GetMapping("info")
    public AjaxResult info() {
        System.out.println("userService = " + SecurityUtils.getUserId());
        return AjaxResult.success(userService.getById(SecurityUtils.getUserId()));
    }



}
